//
//  ViewController.m
//  10804动物匹配
//
//  Created by student on 16/2/25.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property(strong,nonatomic)NSArray *leftList;
@property(strong,nonatomic)NSArray *rightList;
@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;

@property (weak, nonatomic) IBOutlet UILabel *label1;

@property (weak, nonatomic) IBOutlet UILabel *label2;




@end
NSInteger n1,n2;
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.pickerView.showsSelectionIndicator=YES;
    self.leftList=@[[UIImage imageNamed:@"mouse"],
                    [UIImage imageNamed:@"goose"],
                    [UIImage imageNamed:@"cat"],
                    [UIImage imageNamed:@"dog"],
                    [UIImage imageNamed:@"snake"],
                    [UIImage imageNamed:@"bear"],
                    [UIImage imageNamed:@"pig"]];
    self.rightList=@[@"呼噜呼噜",@"吼吼",@"嘶嘶",@"汪汪",@"喵喵",@"哦哦",@"吱吱"];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return 7;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view
{
    if (component==0) {
        UIImageView *imageView=[[UIImageView alloc]initWithImage:self.leftList[row]];
        imageView.contentMode=UIViewContentModeLeft;
        
        return imageView;
     
    }
    else{
        UILabel *label = [[UILabel alloc] init];
        [label setText:self.rightList[row]];
        label.textAlignment =NSTextAlignmentCenter;
        return  label;
    }
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (component==0) {
        n1=row;
        NSArray *animalName=@[@"老鼠",@"鹅",@"猫",@"狗",@"蛇",@"狗熊",@"猪"];
        self.label1.text=[@"你选择的动物名称叫"  stringByAppendingString:animalName[row]];
    }
    else{
        n2=row;
        self.label1.text=[@"你选择的动物的叫声是" stringByAppendingString:self.rightList[row]];
    }
    self.label2.text= n1+n2==6?@"匹配":@"不匹配";

}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    if (component==0) {
        return 90;
    }
    else
    {
        return 90;
    }
    
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 55;
}
@end
